package com.xyht.sca_s.student_manage_system.modules.newTips.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RepeatRequestCheck;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.newTips.entity.req.SmsNewTipsRecordReq;
import com.xyht.sca_s.student_manage_system.modules.newTips.service.SmsNewTipsService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

import static com.xyht.sca_s.student_manage_system.auth.constant.CommonConstant.CLIENT_HEADER;

/**
 * <p>
 * 新消息通知 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-04-20
 */
@RestController
@RequestMapping("/newTips")
@SecretBody
public class SmsNewTipsController {
    @Autowired
    private SmsNewTipsService smsNewTipsService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "消息列表")
    @GetMapping("/list")
    public ResponseResult getTipsList(HttpServletRequest request,
                                      @RequestParam(value = "tips_type") Integer tips_type,
                                      @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        Integer client = Integer.valueOf(request.getHeader(CLIENT_HEADER));
        return smsNewTipsService.getTipsList(user_id, client, tips_type, pageNum, pageSize);
    }

    @ApiModelProperty(value = "通知小红点")
    @GetMapping("/getRedPoint")
    public ResponseResult getRedPoint(HttpServletRequest request) {
        Integer client = Integer.valueOf(request.getHeader(CLIENT_HEADER));
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsNewTipsService.getRedPoint(user_id,client);
    }

    @ApiModelProperty(value = "消息已读")
    @PostMapping("/read")
    @RepeatRequestCheck(name = "tipsRead")
    public ResponseResult tipsRead(@RequestBody SmsNewTipsRecordReq tipsRecordReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsNewTipsService.tipsRead(tipsRecordReq, user_id);
    }

}

